package Problem1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Text {
    private  static List<People> peopleLists = new ArrayList<>();
    public static void main(String[] args) {

        Random random = new Random();
        for (int i = 1; i <= 100 ; i++) {
            //先判断取到的数是否重复了
            int number = random.nextInt(200)+1;
            if (isRepeat(number)){
                i--;
                continue;
            }else{
                People people = new People(number,i);
                peopleLists.add(people);
            }
        }
        System.out.println("原先的排位：");
        System.out.println(peopleLists);

        //除去在位在奇数位置的人，直到剩最后一位。
        //1,2,3,4,5,6,7,8
        //0,1,2,3,4,5,6,7
        //可以看出来就是要保留集合中的奇数位

        while (peopleLists.size() > 1){
            List<People> temp = new ArrayList<>();
            for (int i = 1; i < peopleLists.size(); i+=2) {
                temp.add(peopleLists.get(i));
            }
            peopleLists = temp;
        }
        System.out.println("后来的排位：");
        System.out.println(peopleLists.get(0));

    }
    private static boolean isRepeat(int number){
        for (int i = 0; i < peopleLists.size(); i++) {
            if (peopleLists.get(i).getNumber() == number) {
                return true;
            }
        }
        return false;
    }
}
